package org.dfl.core.model.analysis;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class RSimplePlace {

	private String id;
	private Set<REdge> inputs = new HashSet<REdge>();
	private Set<REdge> outputs = new HashSet<REdge>();
	protected Iterator<REdge> edgesIterator = null;

	public void setId(String s) {
		this.id=s;
	}
	
	public String getId() {
		return this.id;
	}
	
	public boolean addInputEdge(REdge e) {
		return this.inputs.add(e);
	}
	
	public boolean addOutputEdge(REdge e) {
		return this.outputs.add(e);
	}
	
	public boolean removeInputEdge(REdge e) {
		return this.inputs.remove(e);
	}
	
	public boolean removeOutputEdge(REdge e) {
		return this.outputs.remove(e);
	}

	public void removeInputEdges() {
		this.inputs.clear();
	}
	
	public void removeOutputEdges() {
		this.outputs.clear();
	}
	
	public Collection<REdge> getInputEdges() {
		return this.inputs;
	}

	public Collection<REdge> getOutputEdges() {
		return this.outputs;
	}

	public REdge getSingleOutputEdge() {
		if (this.getOutputEdges().size() == 1) {
			edgesIterator = this.getOutputEdges().iterator();
			if (edgesIterator.hasNext())
				return edgesIterator.next();
		}
		return null;
	}
	
	public REdge getSingleInputEdge() {
		if (this.getInputEdges().size() == 1) {
			edgesIterator = this.getInputEdges().iterator();
			if (edgesIterator.hasNext())
				return edgesIterator.next();
		}
		return null;
	}
	
	public REdge getFirstOutputEdge() {
		if (this.getOutputEdges().size() > 0) {
			edgesIterator = this.getOutputEdges().iterator();
			if (edgesIterator.hasNext())
				return edgesIterator.next();
		}
		return null;
	}
	
	public REdge getNextOutputEdge() {
		if (edgesIterator != null) {
			if (edgesIterator.hasNext())
				return edgesIterator.next();
		}
		return null;
	}
}
